﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Windows.Media.Imaging;
using googlemaps;
using System.Threading;
using ClientMobile.SSVService;
using System.Device.Location;

namespace ClientMobile
{
    public class test
    {
        public GeoCoordinate Coords;
        public GeoCoordinateWatcher watcher;
        
        public void Tick(Object stateInfo)
        {

            //string la = watcher.Position.Location.Latitude.ToString();
            //string lo = watcher.Position.Location.Longitude.ToString();
            Singleton s = Singleton.Instance;
            
            watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.Default)
            {
                MovementThreshold = 20
            };
            watcher.PositionChanged += this.watcher_PositionChanged;
            //watcher.StatusChanged += this.watcher_StatusChanged;
            watcher.Start();
            
        }

        public void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
        {
            Service1SoapClient serv = new Service1SoapClient();
            var epl = e.Position.Location;
            Singleton s = Singleton.Instance;
            Coords = new GeoCoordinate(e.Position.Location.Latitude, e.Position.Location.Longitude);
            //serv.AjouterPositionTestCompleted += new System.EventHandler<AjouterPositionTestCompletedEventArgs>(serv_AjouterPositionTestCompleted);
            serv.AjouterPositionTestAsync((float)epl.Latitude,(float) epl.Longitude, s.Chauff.id_chauffeur);

        }

        //public IEnumerable<Etablissement> rechercher(string val)
        //{
        //    var element = XElement.Load("universites.XML");
        //    var result =
        //    from var in element.Descendants("univ")
        //    where ((var.Attribute("Nom").Value.StartsWith(val)))
        //    orderby var.Attribute("Nom").Value
        //    select new Etablissement
        //    {
        //        IdEtab = Convert.ToInt32(var.Attribute("IdEtab").Value),
        //        Nom = var.Attribute("Nom").Value,
        //        Tel = var.Attribute("Tel").Value
        //    };
        //    return result;
        //}


    }
}
